--舞立双刃
local wulishuangren = fk.CreateSkill {
    name = "mcdh_wulishuangren",
    tags = {Skill.Switch},
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

wulishuangren:addEffect('active',{
    switch_skill_name = "mcdh_wulishuangren",
    anim_type = "switch",
    can_use = function(self, player)
        return #lib.getDamageCard(player) > 0 and
                player:getSwitchSkillState("mcdh_wulishuangren", false) == fk.SwitchYang
    end,
    card_filter = Util.FalseFunc,
    target_filter = Util.FalseFunc,
    on_use = function(self, room, effect)
        local player = effect.from
        local cards = player:getCardIds("h")
        local re = {}
        player:showCards(cards)
        for _, id in ipairs(cards) do
            if Fk:getCardById(id).is_damage_card then
                table.insert(re, id)
            end
        end
        room:recastCard(re, player, self.name)
        local number = 2
        while number > 0 do
            local tos = room:askToChoosePlayers(
                    player,
                    {
                        targets = room:getAlivePlayers(),
                        min_num=1,
                        max_num=1,
                        prompt="#wulishuangren-choice:::" .. number,
                        skill_name = self.name,
                        cancelable = false
                    })         
            
            if #tos > 0 then
                local cids = room:askToChooseCards(player,{target=tos[1],min=1,max=number,flag="he",skill_name=self.name})
                room:throwCard(cids, self.name, tos[1], player)
                number = number - #cids
            else
                break
            end
        end
    end
})

wulishuangren:addEffect(fk.DamageCaused,{
    switch_skill_name = "mcdh_wulishuangren",
    anim_type = "switch",
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and target == player and
                player:getSwitchSkillState("mcdh_wulishuangren") == fk.SwitchYin
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askForSkillInvoke(data.from, self.name, nil, "#wulishuangren-damage:" .. data.to.id)
    end,
    on_use = function(self, event, target, player, data)
        data.damage = data.damage + 1
    end
})

wulishuangren:addEffect(fk.DamageInflicted,{
    switch_skill_name = "mcdh_wulishuangren",
    anim_type = "switch",
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and target == player and
                player:getSwitchSkillState("mcdh_wulishuangren") == fk.SwitchYin
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askForSkillInvoke(data.from, self.name, nil, "#wulishuangren-damage:" .. data.to.id)
    end,
    on_use = function(self, event, target, player, data)
        data.damage = data.damage + 1
    end
})

Fk:loadTranslationTable {
    ["mcdh_wulishuangren_yang"] = "舞立双刃",
    [":mcdh_wulishuangren_yang"] = "转换技，①出牌阶段，你可以展示手牌并重铸其中所有伤害牌，然后弃置任意名角色共计至多两张牌；"..
            "②当你造成或受到伤害时，伤害来源可以令此伤害+1。",
    ["#mcdh_wulishuangren_yin"] = "舞立双刃",
    ["#wulishuangren-choice"] = "舞立双刃:选择弃牌角色（还可弃 %arg 张牌）",
    ["#wulishuangren-damage"] = "舞立双刃:令对 %src 的伤害+1"
}

return wulishuangren